package com.hans.scala

object MatchExample {
  def main(args: Array[String]) {
    def honest: PartialFunction[Any, Int] = {
      case i: Int => i
      case s: String => s.toInt
    }
    if (honest.isDefinedAt("1")) {
      println(honest("1"))
    }
    //    println(honest("c")) //NumberFormatException

    val test = (x: String) => {
      x match {
        case "z" => "zhang"
        case "j" => "jun"
        case "t" => "tao"
        case _ => "?"
      }
    }
    println(test("z"))
    println(test("h"))
  }
}